package pyrachnid.view.dnd;

import javax.swing.JLabel;

import pyrachnid.view.listener.DndMapElementListener;

/**
 * 
 */
public class MapElement extends JLabel {

	private static final long serialVersionUID = -3321132284442560447L;
	private DndMapElementListener dndMapElemListener;
	
	/** Attribute **/
	
	private short _typeElement;
	
	/** Getter/Setter **/

	private void setTypeElement(short p_typeElement) {
		this._typeElement = p_typeElement;
	}

	public short getTypeElement() {
		System.out.println("INFO : R�cup�ration du type d'�l�ment. Classe : " + this.getClass().getName());
		return _typeElement;
	}

	/** Constructor **/
	
	public MapElement(String p_name, short p_typeElement) {
		super(p_name);
		
		dndMapElemListener = new DndMapElementListener();
		
		this.setTypeElement(p_typeElement);
		this.setTransferHandler(new ShortTransferHandler());
		this.enableDrag();
		
	}
	
	/** Methods **/
	
	/**
	 * Methods who disable elements
	 */
	public void setEnabled(boolean p_flag) {
		super.setEnabled(p_flag);
		if(p_flag) {
			this.enableDrag();
		} else {
			this.disableDrag();
		}
	}
	
	private void enableDrag() {
        this.addMouseListener(dndMapElemListener);
    }
	
	private void disableDrag() {
        this.removeMouseListener(dndMapElemListener);
    }
	
}
